package com.forhappy.light3ds8.server;

import android.app.IntentService;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

public class ServerIntentService extends IntentService{
	private static final String TAG = "ServerIntentService";
	public static final int CMD_DEFAULT = 0;
	public static final int CMD_SYNC_DATA_BASIC_INFO = 100;
	public static final int CMD_SYNC_DATA_REAL = 101;

	public static final String STR_CMDID = "cmdId";
	public static void startService(Context context, int cmdId, Bundle bd){
		Log.d(TAG, "enter ServerIntentService::startService(cmdID:" + cmdId + ")");
		Intent intent = new Intent(context, ServerIntentService.class);
		if(null != bd){
			intent.putExtras(bd);
		}
		intent.putExtra(STR_CMDID, cmdId);
		context.startService(intent);
	}
	public ServerIntentService() {
		super("ServerIntentService");
	}
	@Override
	protected void onHandleIntent(Intent intent) {
		int cmdId = intent.getIntExtra(STR_CMDID, CMD_DEFAULT);
		Log.d(TAG, "enter ServerIntentService::onHandleIntent(intent:" + intent +
				", cmd:" + cmdId + ")");
		switch (cmdId) {
		case CMD_SYNC_DATA_BASIC_INFO:
			new Job_SyncDataBasicInfo(getBaseContext()).run(); //直接在该线程中执行即可
			break;
		case CMD_SYNC_DATA_REAL:
			int id = intent.getIntExtra("id", 0);
			new Job_SyncDataReal(getBaseContext(), id).run();
			break;
		default:
			Log.e(TAG, "not process for cmdID:" + cmdId);
			break;
		}
	}

}
